package utils;

import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.kernel.events.Event;
import com.itextpdf.kernel.events.IEventHandler;
import com.itextpdf.kernel.events.PdfDocumentEvent;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.layout.Document;

import java.util.Map;

/**
 * @Author LS
 * @Date 2023/5/4 17:56
 * @Description
 **/

public class AutoFillTableHandler implements IEventHandler {

    private final HiPrintItextUtils.UtilData utilData;

    public AutoFillTableHandler(HiPrintItextUtils.UtilData utilData){
        this.utilData = utilData;
    }

    @Override
    public void handleEvent(Event event) {
        final PdfDocumentEvent pdfDocumentEvent = (PdfDocumentEvent) event;
        final PdfDocument pdfDocument = pdfDocumentEvent.getDocument();
        final Document document = new Document(pdfDocument);
        final PdfPage page = pdfDocumentEvent.getPage();

        PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDocument, false);
        Map<String, PdfFormField> formFields = form.getFormFields();

        System.out.println(form);
        System.out.println(formFields);

    }
}
